package com.sample.action;


import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.sample.action.form.BabyForm;
import com.sample.javabean.Baby;
import com.sample.util.Pager;

     /**
     * @author梁桂花
     *
     * 2018-10-24
     */
           public class BabyAction extends BaseAction {
    	       
    	   private final static Log log=LogFactory.getLog(BabyAction.class);
    	 	private Pager<Baby> pageList;
    	 	private String sno;
    	 	private Integer id;
    	 	private String keywords;
    	 
    	 	// 使用new()操作符实例化领域模型
    	 	private Baby baby=new Baby();
    	 	private BabyForm babyForm=new BabyForm();
    	 	
    	 	
    	 	/**
    	 	 * 幼儿信息录入界面
    	 	 * @return
    	 	 * @throws Exception
    	 	 */
    	 	public String inputBaby()throws Exception{
    	 		
    	 		return "inputBaby";
    	 	}
    	 	/**
    	 	 * 
    	 	 * @return
    	 	 * @throws Exception
    	 	 */
    	 	public String save()throws Exception{
    	 		try{
    	 			log.info("添加幼儿信息");
    	 			if(babyForm!=null){
    	 				Baby baby =new Baby();
    	 				 //将persinfoForm中的属性值一一对应persinfo的对应属性
    	 				baby.setName(babyForm.getName());
    	 				baby.setSex(babyForm.getSex());
    	 				baby.setSno(babyForm.getSno());
    	 				baby.setBirthday(babyForm.getBirthday());
    	 				baby.setClassName(babyForm.getClassName());
    	 				baby.setAddress(babyForm.getAddress());
    	 				baby.setTel(babyForm.getTel());
    	 				baby.setPname(babyForm.getPname());
    	 				baby.setCardno(babyForm.getCardno());
    	 			
    	 				
    	 			   //调用方法
    	 				baby.add();
    	 			}
    	 			return SUCCESS;
    	 		}catch (Exception e) {
    	 			e.printStackTrace();
    	 			
    	 		}
    	 		return "inputBaby";
    	 	}
    	 	
    	 	public String list()throws Exception{
    	 		Baby babyModel =new Baby();
    	 		pageList =babyModel.list(page, size, babyForm,keywords);
    	 		return "listBaby";
    	 	}
    	 	public String del()throws Exception{
    	 		try{
    	 			if(babyForm!=null){
    	 				baby.setSno(sno);
    	 				baby.delBaby();	
    	 			}
    	 			return SUCCESS;
    	 		}catch (Exception e) {
    	 			e.printStackTrace();
    	 			throw e;
    	 		}	
    	 	}
    	 	public String editBaby()throws Exception{
    	 		try{
    	 			baby.setId(id);
    	 			baby.load();
    	 			return "editBaby";
    	 		}catch (Exception e) {
    	 			e.printStackTrace();
    	 			throw e;
    	 		}	
    	 	}
    	 	/**
    	 	 * 
    	 	 * @return
    	 	 * @throws Exception
    	 	 */
    	 	public String edit()throws Exception{
    	 		try{
    	 			
    	 			if(babyForm!=null){
    	 					
    	 				
    	 				baby.setId(babyForm.getId());
    	 				baby.setName(babyForm.getName());
    	 				baby.setSex(babyForm.getSex());
    	 				baby.setSno(babyForm.getSno());
    	 				baby.setBirthday(babyForm.getBirthday());
    	 				baby.setClassName(babyForm.getClassName());
    	 				baby.setAddress(babyForm.getAddress());
    	 				baby.setTel(babyForm.getTel());
    	 				baby.setPname(babyForm.getPname());
    	 				baby.setCardno(babyForm.getCardno());
    	 				baby.editBaby();	
    	 			}
    	 			return SUCCESS;
    	 		}catch (Exception e) {
    	 			e.printStackTrace();
    	 			throw e;
    	 		}	
    	 	}
			public Pager<Baby> getPageList() {
				return pageList;
			}
			public void setPageList(Pager<Baby> pageList) {
				this.pageList = pageList;
			}
			public Integer getId() {
				return id;
			}
			public void setId(Integer id) {
				this.id = id;
			}
			public Baby getBaby() {
				return baby;
			}
			public void setBaby(Baby baby) {
				this.baby = baby;
			}
			public BabyForm getBabyForm() {
				return babyForm;
			}
			public void setBabyForm(BabyForm babyForm) {
				this.babyForm = babyForm;
			}
			public static Log getLog() {
				return log;
			}
			public String getSno() {
				return sno;
			}
			public void setSno(String sno) {
				this.sno = sno;
			}
			public String getKeywords() {
				return keywords;
			}
			public void setKeywords(String keywords) {
				this.keywords = keywords;
			}
			
    	
}
